home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / mp / mp_bfffo.c < prev    next >
Text File  |  1991-02-10  |  723b  |  34 lines

  1. /*
  2.      double i; ulong x;
  3.         index of the first non zero bit numbering from left 
  4.       Bit position measured from most significant end
  5.       to the first non zero bit of x
  6.      if (x == 2^i) bfffo(x) == (31 - truncate(i))
  7.        else if (x==0) 32
  8.  
  9.      [truncate (i) chops off the decimal places]
  10.      
  11.      bfffo(0) == 32
  12.      bfffo(1) == 31
  13.      bfffo(2) == 30
  14.      bfffo(3) == 30
  15.      bfffo(4) == 29
  16.      bfffo(5) == 29
  17.      ..
  18.      
  19. */  
  20.  
  21.  
  22. int bfffo(x)
  23.      unsigned long x;
  24. {
  25.   int sc;
  26.   static int tabshi[16]={4,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0};
  27.  
  28.   if(x&(0xffff0000)) sc=0;else {sc=16;x<<=16;}
  29.   if(!(x&(0xff000000))) {sc+=8;x<<=8;}
  30.   if(x&(0xf0000000)) x>>=28;else {sc+=4;x>>=24;}
  31.   sc+=tabshi[x];return sc;
  32. }
  33.  
  34.